window.mp3List=[];
window.typeList=['.mp3'];
window.GetThisList=function(callback){
    chrome.tabs.query({
        active:true,
        currentWindow:true
    },function(e){
        let id=e[0].id;
        for (let i=0;i<mp3List.length;i++){
            let it=mp3List[i];
            if(it.id===id){
                callback(it.list);
            }
        }
    })
}
function GetType(url){
    return url.match(/\.[^\.]+\s*?$/)[0];
}
function GetName(url){
    return url.match(/[^/]+\s*?$/)[0];
}
win_info.create();
chrome.webRequest.onBeforeRequest.addListener(
    function(details) {
        let tabid=details.tabId;
        let url=details.url;
        let name=GetName(url);
        let type=GetType(url);
        typeList.forEach(e=>{
            if(name.indexOf(e)!==-1){
                let index=-1;
                for (let i = 0; i < mp3List.length;i++){
                    let it=mp3List[i];
                    if(it.id===tabid){
                        index=i;
                        break;
                    }
                }
                if(index===-1){
                    //创建
                    mp3List.push({
                        id:tabid,
                        list:[{
                            name,
                            url,
                            type
                        }]
                    });
                }else{
                    //赋值
                    let pd=false;
                    for (let i = 0; i < mp3List[index].list.length;i++){
                        let it= mp3List[index].list[i];
                        if(it.name===name){
                            pd=true;
                            break;
                        }
                    }
                    if(!pd){
                        mp3List[index].list.push({
                            name,
                            url,
                            type
                        });
                    }
                }
            }
        })
    },
    {urls: ["*://*/*"]},
    ["blocking"]);
